package com.uchengwang.ui.utils;

import android.widget.Button;

import com.uchengwang.R;
import com.uchengwang.ui.UChengApplication;

/**
 * Created by U城网 on 2017/7/31.
 */

public class WidgetUtil {
    private static WidgetUtil util;
    private WidgetUtil(){}

    public static WidgetUtil getUtil() {
        if (util == null){
            util = new WidgetUtil();
        }
        return util;
    }

    /**
     * 获取图片是不是竖图
     * */
//    public boolean isVertical(String url){
//        BitmapFactory.Options opts = new BitmapFactory.Options();
//        //只请求图片宽高，不解析图片像素(请求图片属性但不申请内存，解析bitmap对象，该对象不占内存)
//        opts.inJustDecodeBounds = true;
//        //String path = Environment.getExternalStorageDirectory() + "/dog.jpg";
//        BitmapFactory.decodeFile("sdcard/dog.jpg", opts);
//        int imageWidth = opts.outWidth;
//        int imageHeight = opts.outHeight;
//
//
//
//        return false;
//    }

    /**
     * 设置聊天控件状态
     * */
    public void setChatWidget(Button bt){
        bt.setText("聊天");
        bt.setBackgroundResource(R.drawable.selector_chat);
        bt.setTextColor(UChengApplication.getContext().getResources().getColor(R.color.register_next_selector));
    }
    /**
     * 设置关注控件状态 true是关注状态 false是未关注状态
     * @param type 1 关注 2 关联
     * */
    private void setWidgetControl(Button bt, boolean isAtten, int type){
        if (isAtten){
            switch (type){
                case 1:
                    bt.setText("已关注");
                    break;
                case 2:
                    bt.setText("已关联");
                    break;
                case 3:
                    bt.setText("已订阅");
                    break;
            }
//            bt.setBackgroundResource(R.drawable.selector_no_atten);
//            bt.setTextColor(UChengApplication.getContext().getResources().getColor(R.color.delete_selector));
            bt.setTextColor(UChengApplication.getContext().getResources().getColor(R.color.selector_login_color));

        }else {
            switch (type){
                case 1:
                    bt.setText("+关注");
                    break;
                case 2:
                    bt.setText("关联");
                    break;
                case 3:
                    bt.setText("订阅");
                    break;
            }
//            bt.setBackgroundResource(R.drawable.selector_friends);
            bt.setTextColor(UChengApplication.getContext().getResources().getColor(R.color.register_user_selector));
        }
    }

    /**
     * @param type 1加群
     * */
    private void setControl(Button bt, boolean isAtten, int type){
        if (isAtten){
            switch (type){
                case 1://已加群
                    bt.setText("聊天");
                    break;
            }
            bt.setBackgroundResource(R.drawable.selector_chat);
            bt.setTextColor(UChengApplication.getContext().getResources().getColor(R.color.register_next_selector));
        }else {
            switch (type){
                case 1:
                    bt.setText("加群");
                    break;
            }
            bt.setBackgroundResource(R.drawable.selector_friends);
            bt.setTextColor(UChengApplication.getContext().getResources().getColor(R.color.register_user_selector));
        }
    }

    //关注
    public void setAttenWidget(Button bt, boolean isAtten){
        setWidgetControl(bt, isAtten, 1);
    }
    //关联
    public void setLinkWidget(Button bt, boolean isLink){
        setWidgetControl(bt, isLink, 2);
    }

    //订阅
    public void setPaidWidget(Button bt, boolean isPaid){
        setWidgetControl(bt, isPaid, 3);
    }

    //加群
    public void setGroupWidget(Button bt, boolean isAdd){
        setControl(bt, isAdd, 1);
    }

}
